//
//  SharedViewController.m
//  CenturyInterconnection
//
//  Created by 郭先生 on 16/4/19.
//  Copyright © 2016年 Shanghai DuRui Information Technology Company. All rights reserved.
//

#import "InfoViewController.h"
#import "NSString+Common.h"

@interface InfoViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong) UITableView *tableView;
@end

@implementation InfoViewController
-(UITableView *)tableView{
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, KScreenWidth, KScreenHeight) style:UITableViewStyleGrouped];
    _tableView.delegate =self;
    _tableView.dataSource = self;
    return _tableView;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeNaviButton];
    [self.view addSubview:self.tableView];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
        cell.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight-ACTUAL_HEIGHT(64));
    }
    //背景
    UIView * bgView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth ,KScreenHeight-ACTUAL_HEIGHT(64))];
    //商品价格
    UILabel *priceLabel = [[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_HEIGHT(20), ACTUAL_HEIGHT(20), ACTUAL_WIDTH(330), ACTUAL_HEIGHT(40))];
    priceLabel.text =self.priceStr;
//    priceLabel.backgroundColor=[UIColor yellowColor];
    priceLabel.font = [UIFont systemFontOfSize:22];
    priceLabel.textAlignment=0;
    [bgView addSubview:priceLabel];
    
    //描述
    CGFloat height = MIN(999, [self.describeStr getHeightWithFont:[UIFont systemFontOfSize:18] constrainedToSize:CGSizeMake(300, CGFLOAT_MAX)]);//利用第三方工具算出内容所需高度
    
    UILabel *descriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), priceLabel.bottom+ACTUAL_HEIGHT(30), ACTUAL_WIDTH(330),height)];
    descriptionLabel.text = self.describeStr;
    descriptionLabel.numberOfLines=0;
    descriptionLabel.font = [UIFont systemFontOfSize:18];
//    descriptionLabel.backgroundColor=[UIColor redColor];
    descriptionLabel.textAlignment=0;
    [bgView addSubview:descriptionLabel];
    
    //尺码
    UILabel * sizeLabel = [[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), descriptionLabel.bottom+ACTUAL_HEIGHT(30), ACTUAL_WIDTH(330), ACTUAL_HEIGHT(15))];
    sizeLabel.text = [NSString stringWithFormat:@"The Model Is %@ ",self.modelStr];
    sizeLabel.font= [UIFont systemFontOfSize:13.00];
//    sizeLabel.backgroundColor=[UIColor blueColor];
    sizeLabel.textAlignment=0;
    [bgView addSubview:sizeLabel];
    
    //编号
     UILabel * REFLabel = [[UILabel alloc]initWithFrame:CGRectMake(ACTUAL_WIDTH(20), descriptionLabel.bottom+ACTUAL_HEIGHT(65), ACTUAL_WIDTH(330), ACTUAL_HEIGHT(40))];
    REFLabel.text = self.titleStr;
    REFLabel.font = [UIFont systemFontOfSize:13];
    REFLabel.numberOfLines=2;
//    REFLabel.backgroundColor=[UIColor greenColor];
    REFLabel.textAlignment=0;
    [bgView addSubview:REFLabel];
    
    [cell addSubview:bgView];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return KScreenHeight-ACTUAL_HEIGHT(64);
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0001;
}

-(void)makeNaviButton{
    
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    UIButton *RightButton = [UIButton buttonWithType:UIButtonTypeSystem];
    
    
    [RightButton setBackgroundImage:[UIImage imageNamed:@"nav_close"] forState:0];
    [leftButton setTitle:@"INFO" forState:0];
    
    leftButton.frame=CGRectMake(0, 0, ACTUAL_WIDTH(50), ACTUAL_HEIGHT(20));
    RightButton.frame = CGRectMake(ACTUAL_WIDTH(320), 0, ACTUAL_WIDTH(20), ACTUAL_HEIGHT(20));
    
    [RightButton addTarget:self action:@selector(comeBack) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem*item=[[UIBarButtonItem alloc]initWithCustomView:leftButton];
    UIBarButtonItem*item1 = [[UIBarButtonItem alloc]initWithCustomView:RightButton];
    
    self.navigationItem.leftBarButtonItem=item;
    self.navigationItem.rightBarButtonItem=item1;
}

-(void)comeBack{
    
    [self.navigationController popViewControllerAnimated:YES];
    
}



@end
